package com.lv.dhart.base;

import android.view.View;

import androidx.appcompat.widget.SearchView;

import com.lv.dhart.R;

import java.io.Serializable;

public abstract class AbsTopNavigationTabBaseFragmentWithSearchView<B extends Serializable>
        extends AbsTopNavigationTabBaseFragment<B> {
    protected SearchView searchView;

    @Override
    protected void initView(View view) {
        super.initView(view);
        searchView = view.findViewById(R.id.search_view);
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                // 在这里处理搜索提交事件

                return onSearchViewQueryTextSubmitListener(query);
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // 在这里处理搜索内容变化事件
                return onSearchViewQueryTextChangeListener(newText);
            }
        });
        searchView.setOnCloseListener(() -> {
            onSearchViewCloseListener();
            return false;
        });
        searchView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onSearchViewClickListener(v);
            }
        });
    }

    @Override
    protected int getFragmentLayout() {
        return R.layout.layout_common_list_with_search;
    }

    protected abstract boolean onSearchViewQueryTextChangeListener(String newText);

    protected abstract boolean onSearchViewCloseListener();
    protected abstract boolean onSearchViewClickListener(View v);

    protected abstract boolean onSearchViewQueryTextSubmitListener(String query);

}
